// 6.68 已知一棵树的由根至叶子结点按层次输入的结点序列及每个结点的度（每层中自左至右输入），试写出构造此树的孩子-兄弟链表的算法。
#include <stdio.h>
#include <stdlib.h>
#include "E:\Desktop\data_struct\5TREE\1_bin_tree\creat.h"
void fun_6_68(tree *&root, int data[], int degree[], int n)
{
	int front, rear;
	front = rear = 0; //节点队列指针
	int k = 0;		  //标记data[] 队列
	root = (tree *)malloc(sizeof(tree));
	root->data = data[k++];
	root->left = root->right = NULL;
	tree *queue[20];
	queue[rear++] = root;
	while (front < rear)
	{
		tree *t = queue[front++];
		for (int i = 0; i < degree[front - 1]; i++)
		{
			tree *node = (tree *)malloc(sizeof(tree));
			node->data = data[k++];
			node->left = node->right = NULL;
			node->right = t->left;
			t->left = node;
			queue[rear++] = node;
		}
	}
}

int main()
{
	/*******************code*******************/
	int data[] = {0, 1, 2, 3, 4, 5};
	int n = 6;
	int degree[] = {3, 2, 0, 0, 0, 0};
	tree *root;
	fun_6_68(root, data, degree, n);
	/******************************************/
	printf("\n\n****************************\n");
	printf("Press Enter key to continue\n");
	getchar();
	return 0;
	/******************************************/
}
